package com.tianzeculture.stagebao.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.network.util.DensityUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/5/24 0024.
 */

public class ShareDialog implements View.OnClickListener {

    private Dialog dialog;
    private OnSelectClickListener onSelectClickListener;

    public ShareDialog(Context context) {
        init(context);
    }

    private void init(final Context context) {
        dialog = new Dialog(context, R.style.DialogPushUpInAnimStyle);
        dialog.setContentView(R.layout.dialog_share);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);

        Window window = dialog.getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();

        layoutParams.width = DensityUtil.getScreenWidth(context);
        layoutParams.gravity = Gravity.BOTTOM;
        window.setAttributes(layoutParams);

        TextView tvCancel = dialog.findViewById(R.id.tvCancel);
//        TextView tvAllShare = dialog.findViewById(R.id.tvAllShare);
        TextView tvWechat = dialog.findViewById(R.id.tvWechat);
        TextView tvFriend = dialog.findViewById(R.id.tvFriend);
        TextView tvQQ = dialog.findViewById(R.id.tvQQ);
        TextView tvKongjian = dialog.findViewById(R.id.tvKongjian);
        TextView tvWeibo = dialog.findViewById(R.id.tvWeibo);

        tvCancel.setOnClickListener(this);
        tvWechat.setOnClickListener(this);
        tvFriend.setOnClickListener(this);
        tvQQ.setOnClickListener(this);
        tvKongjian.setOnClickListener(this);
        tvWeibo.setOnClickListener(this);
    }


    private void clickShare(int type) {
        if (onSelectClickListener != null) {
            onSelectClickListener.onOk(type);
        }
        dismiss();
    }


    /**
     *
     */
    public void show() {
        dialog.show();
    }

    /**
     *
     */
    public void dismiss() {
        dialog.dismiss();
        if (onSelectClickListener != null) {
            onSelectClickListener.onCancel();
        }
    }

    public OnSelectClickListener getOnSelectClickListener() {
        return onSelectClickListener;
    }

    public void setOnSelectClickListener(OnSelectClickListener onSelectClickListener) {
        this.onSelectClickListener = onSelectClickListener;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tvCancel:
                dismiss();
                break;
            case R.id.tvWechat:
                clickShare(1);
                break;
            case R.id.tvFriend:
                clickShare(2);
                break;
            case R.id.tvQQ:
                clickShare(3);
                break;
            case R.id.tvKongjian:
                clickShare(4);
                break;
            case R.id.tvWeibo:
                clickShare(5);
                break;
        }
    }


    public interface OnSelectClickListener {
        void onOk(int shareType);
        void onCancel();
    }


}
